package com.vf.admin.miaodong.controller;

import com.vf.admin.common.BaseController;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppGiftReward;
import com.vf.admin.miaodong.service.AfterGameGiftRecordService;
import com.vf.admin.miaodong.service.AfterGiftRewardService;
import com.vf.admin.utils.StringEx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 打赏管理
 */
@Controller
@RequestMapping("/after/reward")
public class AfterRewardController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    AfterGiftRewardService afterGiftRewardService;

    @Autowired
    AfterGameGiftRecordService afterGameGiftRecordService;

    /**
     * 打赏管理列表
     * @return
     */
    @RequestMapping("/list")
    public String list(SplitPageBean splitPage, String nick, String dsnick, String startDate, String endDate, Integer roomcode){
        try{
            Map<String, Object> map = new HashMap<>();
            map.put("nick", nick);
            map.put("dsnick", dsnick);
            map.put("startDate", startDate);
            map.put("endDate", endDate);
            map.put("roomcode", roomcode);
            List<AppGiftReward> rewards = afterGiftRewardService.list(map, splitPage);
            Long reward = afterGiftRewardService.findListByInfo(map);
            if (rewards.size() < 0) {
                return sucess("/web/after/reward/list");
            } else {
                request.setAttribute("allmoney", reward);
                request.setAttribute("list",rewards);
                request.setAttribute("splitPage",splitPage);
                request.setAttribute("nick",nick);
                request.setAttribute("dsnick",dsnick);
                request.setAttribute("startDate",startDate);
                request.setAttribute("endDate",endDate);
                request.setAttribute("roomcode",roomcode);
                return this.sucess("/web/after/reward/list");
            }
        }catch (Exception e){
            logger.error("获取打赏管理列表异常",e);
            return this.error("系统繁忙");
        }
    }


    /**
     * 礼物详情
     * @param id
     * @return
     */
    @RequestMapping("/details")
    public String liwuList(Integer id){
        try{
            if(StringEx.isNull(id)){
                return this.sucess("/web/after/reward/liwuList");
            }
            AppGiftReward appGift =  afterGiftRewardService.get(id);
            request.setAttribute("list",appGift);
            return this.sucess("/web/after/reward/liwuList");
        }catch (Exception e){
            logger.error("礼物详情异常",e);
            return this.error("系统繁忙");
        }
    }
}
